package com.knowledge.knowledge_notes.controller;

import com.knowledge.knowledge_notes.common.ResultVo;
import com.knowledge.knowledge_notes.pojo.LoginUser;
import com.knowledge.knowledge_notes.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/api/admin/user")
    public ResultVo listUsers() {
        return ResultVo.OK(userService.list());
    }

    @PutMapping("/api/admin/user")
    public ResultVo editUser(@RequestBody LoginUser requestUser) {
        try {
            userService.editUser(requestUser);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.FAIL("修改用户信息异常");
        }
        return ResultVo.OK("修改用户信息成功");
    }

}
